import allure
from selenium.webdriver.common.by import By

from base.base_page import BasePage


class PageRegister(BasePage):
    #1、输入手机号码
    @allure.step("1、输入手机号码")
    def __input_phone(self,phone):
        self.input_page_element((By.CSS_SELECTOR,'#username'), phone)

    #输入验证码
    @allure.step("2、输入验证码")
    def __input_verify_code(self,verify_code):
        self.input_page_element((By.CSS_SELECTOR,"input[placeholder='图像验证码']"), verify_code)
    #输入密码
    @allure.step("3、输入密码")
    def __input_password(self,password):
        self.input_page_element((By.CSS_SELECTOR,'#password'), password)
    #输入确认密码
    @allure.step("4、输入确认密码")
    def __input_confirm_password(self,confirm_password):
        self.input_page_element((By.CSS_SELECTOR,'#password2'), confirm_password)

    #推荐人手机
    @allure.step("5、输入推荐人手机")
    def __input_recommend_phone(self,recommend_phone):
        self.input_page_element((By.CSS_SELECTOR,"input[placeholder='请输入手机号码'][name='invite']"), recommend_phone)

    #点击注册按钮
    @allure.step("6、点击注册按钮")
    def __click_register_button(self):
        self.click_page_element((By.CSS_SELECTOR,'.regbtn.J_btn_agree'))

    #注册成功
    def get_register_success_text(self):
        return self.get_page_element_text((By.CSS_SELECTOR,'.red.userinfo'))
    #注册失败
    def get_register_fail_text(self):
        return self.get_page_element_text((By.CSS_SELECTOR,".layui-layer-content.layui-layer-padding"))

    #手机号码注册
    def phone_register(self,phone,password,verify_code,confirm_password,recommend_phone):
        self.__input_phone(phone) #输入手机号码
        self.__input_verify_code(verify_code) #输入验证码
        self.__input_password(password) #输入密码
        self.__input_confirm_password(confirm_password) #输入确认密码
        self.__input_recommend_phone(recommend_phone) #输入推荐人手机
        self.__click_register_button() #点击注册按钮

    def phone_register1(self, username, password, verify_code, confirm_password, recommend_phone):
        self.input_page_element((By.CSS_SELECTOR, '#username'), username)
        self.input_page_element((By.CSS_SELECTOR,"input[placeholder='图像验证码']"), verify_code)
        self.input_page_element((By.CSS_SELECTOR, '#password'), password)